//
//  BlueToothSDK.h
//  BlueToothSDK
//
//  Created by 元潮 谢 on 16/10/8.
//  Copyright © 2016年 元潮 谢. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>



//当前操作
typedef NS_ENUM(NSInteger, CurrentOperatorState)
{
    
    Current_Operator_State_Normal = 0,
    
    Current_Operator_State_Set_Key,                 //设置key
    Current_Operator_State_Unlock,                  //开锁
    Current_Operator_State_Unlock_end,              //开锁结束
    Current_Operator_State_Search_And_Unlock,       //搜索和开锁一体
    
};

typedef NS_ENUM(NSInteger, PStoneErrorCode)
{
    
    PStoneErrorCode_NO_Peripheral,                  //没有发现对应设备
    
};

//一些回调
@protocol PStoneBlueToothSDKDelegate <NSObject>


//蓝牙搜索，连接相关回调
-(void)callbackPeripheralFound:(CBPeripheral *)peripheral RSSI:(NSNumber*)rssi lockName:(NSString*)lockName mac:(NSString*)mac advertisementData:(NSDictionary *)advertisementData;
-(void)callbackConnect:(CBPeripheral *)peripheral lockName:(NSString*)lockName;
-(void)callbackDisconnect:(NSString*)lockName;



//操作回调
-(void)callbackSetLockKeyResult:(Byte)result;
-(void)callbackUnlockResult:(Byte)result;
-(void)callbackWithError:(PStoneErrorCode)errorCode desc:(NSString*)desc;
-(void)callbackSetupBlueTooth:(CBManagerState)state;


@end



@interface BlueToothSDK : NSObject


//TODO 需要删除这个
#define fileServiceString       @"ff80"
#define fileSubWriteString      @"ff86"
#define fileSubReadString       @"ff86"
#define fileService             0xff80
#define fileSubWrite            0xff86
#define fileSubRead             0xff86


//ff80
//ff86

//TODO 需要删除这个
@property (nonatomic, assign) id <PStoneBlueToothSDKDelegate> delegate;

@property (nonatomic)int currentServiceUUID;
@property (nonatomic)int currentCharacteristicUUID;
@property (nonatomic, assign)CBPeripheral * currentPeripheral;
//@property (nonatomic, assign)Byte * currentKey;
@property (nonatomic, assign)NSString * currentKey;
@property (nonatomic, assign)NSString * macAddressUnlock;
@property (nonatomic)float connectTime;




//TODO 需要删除这个
+ (BlueToothSDK *)shared;



//-------------蓝牙操作---------------

/** 启动蓝牙
 */
-(void)setupBlueTooth;

/** 开始扫描附近的蓝牙
 */
-(void)scan;

/** 停止扫描附近的蓝牙
 */
-(void)stopScan;

/** 连接蓝牙
 */
-(void)connect:(CBPeripheral *)peripheral;

/** 断开蓝牙连接
 */
-(void) disconnect:(CBPeripheral *)peripheral;



-(void)setLockKey:(NSString*)key;
//-(void)unLockKey:(NSString*)key unlockID:(NSString*)unlockID;
//-(void)getUnlockIDWithKey:(NSString*)key;
-(void)unlockWithKey:(NSString*)key;
-(void)unlockWithKey:(NSString *)key macAddress:(NSString *)macAddress connectTime:(float)connectTime;

@end
